package com.example.demo.controller;

import com.example.demo.dao.UserDao;
import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shenb
 * @date 2022-06-29 14:26
 */
@RestController
@RequestMapping("users")
public class UserController {

    @Autowired
    private UserDao userDao;

    @GetMapping()
    @ResponseBody
    public List<User> list() {
        User user = new User();
        user.setAge(8);
        user.setName("Tom");
        Map<String, String> labels = new HashMap<>();
        labels.put("like", "tv");
        user.setLabels(labels);
        userDao.save(user);


        List<User> all = userDao.findAll();
        return all;
    }
}
